package com.zscat.mallplus.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zscat.mallplus.annotation.IgnoreAuth;
import com.zscat.mallplus.dms.entity.DmsOrder;
import com.zscat.mallplus.dms.service.IDmsBannerService;
import com.zscat.mallplus.dms.service.IDmsOrderService;
import com.zscat.mallplus.enums.OrderStatus;
import com.zscat.mallplus.utils.CommonResult;
import com.zscat.mallplus.utils.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@Api(tags = "QsgOrderController", description = "订单管理")
@RequestMapping("/api/dms/order")
public class QsgOrderController {

    @Autowired
    private IDmsOrderService orderService;

    @IgnoreAuth
    @GetMapping(value = "/getOrderById")
    public Object getOrderById(Long id) {
        try {
            DmsOrder order = orderService.getById(id);
            order.setSource("share");
            if (order.getOrderStatus()== OrderStatus.HAS_PAYMONEY.getValue()){
                Date startTime = DateUtil.StringToDate(order.getStartTime(),"yyyy/MM/dd HH:mm");
                Date endTime = DateUtil.StringToDate(order.getEndTime(),"yyyy/MM/dd HH:mm");
                if (new Date().compareTo(startTime)<0||new Date().compareTo(endTime)>0){
                    order.setShowStatus(1);
                }
            }
            return new CommonResult().success(order);
        }catch (Exception e){
            e.printStackTrace();
            return new CommonResult().failed();
        }
    }
}
